﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.ETL.Properties;

namespace Workflows.Components.ETL
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class DelimitedTextFileReaderComponent:WorkflowComponentBase
	{
		#region ctor
		/// <summary>
		/// 
		/// </summary>
		public DelimitedTextFileReaderComponent()
			: base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.ETL.ToString();
			this.ComponentName = "Delimited Text Reader";
			this.Description = "Read flat file into data table";
			this.ComponentIcon = Resources.notepad;
			this.ComponentImage = Resources.RecordSetDest_201;

		    this._Instruction =
		        new DelimitedTextFileReaderInstruction(
		            this.ComponentID, Guid.Empty, string.Empty,
		            new Delimiter(SpecialDelimiter.Tab, ""), 1,
		            string.Empty, string.Empty, string.Empty, true, true);
			this._Output = new DelimitedTextFileReaderOutput(
				this.ComponentID, Guid.Empty, 0);
		}
		#endregion

		#region Overrides of WorkflowComponentBase

		private DelimitedTextFileReaderInstruction _Instruction;
		/// <summary>an object that encapsulate instruction settings.</summary>
		public override InstructionBase Instruction
		{
			get { return _Instruction; }
			set { _Instruction=(DelimitedTextFileReaderInstruction)value; }
		}

		private DelimitedTextFileReaderOutput _Output;
		/// <summary>an object to encapsulate output</summary>
		public override ResultBase Output
		{
			get { return _Output; }
			set { _Output=(DelimitedTextFileReaderOutput)value; }
		}

		#endregion

		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
			this.Instruction.Serialize(ref xDoc, ref xNode);
			return xNode;
		}

		public override WorkflowComponentBase Instantiate(XmlNode xNode)
		{
			DelimitedTextFileReaderComponent component = (DelimitedTextFileReaderComponent)base.Instantiate(xNode);
			component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
			return component;
		}
	}
}
